package sxt.service.impl;

import sxt.mapper.GoodsMapper;
import sxt.service.GoodsService;
import sxt.util.DBUtil;
import vo.Goods;

import java.util.List;

public class GoodsServiceImpl implements GoodsService {
    @Override
    public List<Goods> findAllGoods() {
        //1.创建会话,得到mapper对象
        GoodsMapper mapper = DBUtil.getSqlSession().getMapper(GoodsMapper.class);

        //2.通过mapper对象获取数据
        List<Goods> goodsList = mapper.selectGoods();

        //3.关闭session会话
        DBUtil.closeAll();

        //4.return数据
        return goodsList;
    }

    @Override
    public List<Goods> findnewItemGoods() {
        //1.创建会话，得到含有goodsmapper的mapper对象
        GoodsMapper mapper=DBUtil.getSqlSession().getMapper(GoodsMapper.class);

        //2.通过mapper对象获取数据
        List<Goods> goodsnewItem =mapper.selectNewItemGoods();

        //3.关闭session会话
        DBUtil.closeAll();

        //4.
        return goodsnewItem;

    }

    @Override
    public Goods findOneGoods(String id) {
        GoodsMapper mapper=DBUtil.getSqlSession().getMapper(GoodsMapper.class);

        Goods oneGoods = mapper.selectOneGoods(id);

        DBUtil.closeAll();

        return oneGoods;
    }
}
